package com.uzai.console.web.tiktok;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceProductKeyEnum;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.common.enums.TiktokDeviceProductKeyEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.dto.devicegroup.DeviceGroupIdDto;
import com.uzai.console.dto.devicegroup.DeviceGroupInfoDto;
import com.uzai.console.dto.devicegroup.DeviceGroupQuery;
import com.uzai.console.dto.module.deviceproduct.DeviceProductQuery;
import com.uzai.console.dto.tiktok.devicetiktokinfo.*;
import com.uzai.console.dto.wechatprivate.configplan.ConfigPlanQuery;
import com.uzai.console.dto.wechatprivate.devicewechatinfo.*;
import com.uzai.console.entity.ConfigPlan;
import com.uzai.console.entity.DeviceGroup;
import com.uzai.console.entity.DeviceTiktokInfo;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.*;
import com.uzai.console.service.devicegroup.DeviceGroupService;
import com.uzai.console.service.tiktok.DeviceTiktokInfoService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.devicegroup.DeviceGroupInfoVo;
import com.uzai.console.vo.deviceproduct.DeviceProductVo;
import com.uzai.console.vo.tiktok.devicetiktokinfo.DeviceTiktokInfoAddVo;
import com.uzai.console.vo.tiktok.devicetiktokinfo.DeviceTiktokInfoVo;
import com.uzai.console.vo.user.wechatuser.WechatUserDeciceInfoVo;
import com.uzai.console.vo.wechatprivate.devicewechatinfo.DeviceAmountVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 抖音设备机器人管理
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "抖音设备机器人管理",tags = "抖音设备|机器人管理")
@ApiSort(5)
@RestController
public class DeviceTiktokInfoController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(DeviceTiktokInfoController.class);

    @Autowired
    private DeviceTiktokInfoService deviceTiktokInfoService;
    @Autowired
    private DeviceGroupService deviceGroupService;
    @Autowired
    private DeviceGroupMapper deviceGroupMapper;
    @Autowired
    private UserTypeGroupMapper userTypeGroupMapper;
    @Autowired
    private ConfigPlanMapper configPlanMapper;
    @Autowired
    private DevicePriceMapper devicePriceMapper;
    @Autowired
    private DeviceTiktokInfoMapper deviceTiktokInfoMapper;

    @ApiOperation(value = "分页查询抖音设备机器人列表", notes = "分页查询抖音设备机器人列表", response = DeviceTiktokInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/deviceTiktokInfo/findDeviceTiktokInfoList")
    public Object findDeviceTiktokInfoList(@RequestBody DeviceTiktokInfoQuery deviceTiktokInfoQuery){
        return deviceTiktokInfoService.findDeviceTiktokInfoList(deviceTiktokInfoQuery);
    }

    @ApiOperation(value = "查询抖音设备机器人信息", notes = "查询抖音设备机器人信息", response = DeviceTiktokInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/deviceTiktokInfo/findDeviceTiktokInfo")
    public Object findDeviceTiktokInfoInfo(@RequestBody DeviceTiktokInfoIdDto deviceTiktokInfoIdDto){
        return deviceTiktokInfoService.findDeviceTiktokInfoInfo(deviceTiktokInfoIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加抖音设备机器人", notes = "添加抖音设备机器人", response = DeviceTiktokInfoAddVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/deviceTiktokInfo/addDeviceTiktokInfo")
    public Object addDeviceTiktokInfo(@RequestBody DeviceTiktokInfoAddDto deviceTiktokInfoAddDto){
        deviceTiktokInfoService.addDeviceTiktokInfo(deviceTiktokInfoAddDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "编辑抖音设备机器人信息", notes = "编辑抖音设备机器人信息")
    @ApiOperationSupport(order = 3)
    @PostMapping("/deviceTiktokInfo/updateDeviceTiktokInfo")
    public Object updateDeviceTiktokInfo(@RequestBody DeviceTiktokInfoDto deviceTiktokInfoDto){
        deviceTiktokInfoService.updateDeviceTiktokInfo(deviceTiktokInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量修改抖音设备机器人", notes = "批量修改抖音设备机器人")
    @ApiOperationSupport(order = 3)
    @PostMapping("/deviceTiktokInfo/batchUpdateDeviceTiktokInfo")
    public Object batchUpdateDeviceTiktokInfo(@RequestBody DeviceTiktokInfoBatchDto deviceTiktokInfoBatchDto){
        deviceTiktokInfoService.batchUpdateDeviceTiktokInfo(deviceTiktokInfoBatchDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "批量删除抖音设备机器人", notes = "批量删除抖音设备机器人")
    @ApiOperationSupport(order = 4)
    @PostMapping("/deviceTiktokInfo/delDeviceTiktokInfo")
    public Object delDeviceTiktokInfo(@RequestBody DeviceTiktokInfoDelDto deviceTiktokInfoDelDto){
        return deviceTiktokInfoService.delDeviceTiktokInfo(deviceTiktokInfoDelDto);
    }

    @ApiOperation(value = "分页查询抖音设备机器人分组列表", notes = "分页查询抖音设备机器人分组列表", response = DeviceGroupInfoVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/deviceTiktokInfo/findDeviceGroupList")
    public Object findDeviceGroupList(@RequestBody DeviceGroupQuery deviceGroupQuery){
        deviceGroupQuery.setDeviceType(DeviceTypeEnum.TIKTOK.getKey());
        return deviceGroupService.findDeviceGroupList(deviceGroupQuery);
    }

    @ApiOperation(value = "查询抖音设备机器人分组详情", notes = "查询抖音设备机器人分组详情", response = DeviceGroupInfoVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/deviceTiktokInfo/findDeviceGroupInfo")
    public Object findDeviceGroupInfo(@RequestBody DeviceGroupIdDto deviceGroupIdDto){
        return deviceGroupService.findDeviceGroupInfo(deviceGroupIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加抖音设备机器人分组", notes = "添加抖音设备机器人分组")
    @ApiOperationSupport(order = 7)
    @PostMapping("/deviceTiktokInfo/addDeviceGroup")
    public Object addDeviceGroup(@RequestBody DeviceGroupInfoDto deviceGroupInfoDto){
        //添加抖音设备机器人分组
        deviceGroupInfoDto.setDeviceType(DeviceTypeEnum.TIKTOK.getKey());
        deviceGroupService.addDeviceGroup(deviceGroupInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "编辑抖音设备机器人分组", notes = "编辑抖音设备机器人分组")
    @ApiOperationSupport(order = 8)
    @PostMapping("/deviceTiktokInfo/updateDeviceGroup")
    public Object updateDeviceGroup(@RequestBody DeviceGroupInfoDto deviceGroupInfoDto){
        deviceGroupInfoDto.setDeviceType(DeviceTypeEnum.TIKTOK.getKey());
        deviceGroupService.updateDeviceGroup(deviceGroupInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除抖音设备机器人分组", notes = "删除抖音设备机器人分组")
    @ApiOperationSupport(order = 9)
    @PostMapping("/deviceTiktokInfo/deleteDeviceGroup")
    public Object deleteDeviceGroup(@RequestBody DeviceGroupIdDto deviceGroupIdDto){
        deviceGroupService.deleteDeviceGroup(deviceGroupIdDto);
        return true;
    }

    @ApiOperation(value = "查询抖音设备机器人分组下拉选择框列表", notes = "查询抖音设备机器人分组下拉选择框列表")
    @ApiOperationSupport(order = 10)
    @PostMapping("/deviceTiktokInfo/findDeviceGroupSelect")
    public Object findDeviceGroupSelect(){
        List<SelectKeyVo> selectIdVoList = new ArrayList<>();
        DeviceGroupQuery deviceGroupQuery = new DeviceGroupQuery();
        deviceGroupQuery.setMerId(getLoginInfo().getMerId());
        deviceGroupQuery.setDeviceType(DeviceTypeEnum.TIKTOK.getKey());
        List<DeviceGroup> deviceGroupList = deviceGroupMapper.findByList(deviceGroupQuery);
        if(deviceGroupList != null){
            for (DeviceGroup deviceGroup : deviceGroupList){
                SelectKeyVo selectKeyVo = new SelectKeyVo();
                selectKeyVo.setKey(String.valueOf(deviceGroup.getId()));
                selectKeyVo.setValue(deviceGroup.getName());
                selectIdVoList.add(selectKeyVo);
            }
        }
        return selectIdVoList;
    }

    @ApiOperation(value = "查询抖音设备配置方案下拉选择框列表", notes = "查询抖音设备配置方案下拉选择框列表")
    @ApiOperationSupport(order = 12)
    @PostMapping("/deviceTiktokInfo/findConfigPlanSelect")
    public Object findConfigPlanSelect(){
        List<SelectKeyVo> selectIdVoList = new ArrayList<>();
        ConfigPlanQuery configPlanQuery = new ConfigPlanQuery();
        configPlanQuery.setMerId(getLoginInfo().getMerId());
        configPlanQuery.setDeviceType(DeviceTypeEnum.TIKTOK.getKey());
        List<ConfigPlan> configPlanList = configPlanMapper.findByList(configPlanQuery);
        if(configPlanList != null){
            for (ConfigPlan configPlan : configPlanList){
                SelectKeyVo selectKeyVo = new SelectKeyVo();
                selectKeyVo.setKey(String.valueOf(configPlan.getId()));
                selectKeyVo.setValue(configPlan.getName());
                selectIdVoList.add(selectKeyVo);
            }
        }
        return selectIdVoList;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.BUY)
    @ApiOperation(value = "购买抖音设备机器人授权", notes = "购买抖音设备机器人授权", response = DeviceTiktokInfoAddVo.class)
    @ApiOperationSupport(order = 19)
    @PostMapping("/deviceTiktokInfo/buyDeviceAuth")
    public Object buyDeviceAuth(@RequestBody DeviceTiktokInfoBuyAuthDto deviceTiktokInfoBuyAuthDto){
        return deviceTiktokInfoService.buyDeviceAuth(deviceTiktokInfoBuyAuthDto);
    }

    @ApiOperation(value = "查询添加抖音设备机器人和购买授权总金额", notes = "查询添加抖音设备机器人和购买授权总金额", response = DeviceAmountVo.class)
    @ApiOperationSupport(order = 20)
    @PostMapping("/deviceTiktokInfo/getAmount")
    public Object getAmount(@RequestBody DeviceAmountDto deviceAmountDto){
        return deviceTiktokInfoService.getAmount(deviceAmountDto);
    }

    @ApiOperation(value = "查询抖音设备功能类型列表", notes = "查询抖音设备功能类型列表", response = DeviceProductVo.class)
    @ApiOperationSupport(order = 21)
    @PostMapping("/deviceTiktokInfo/deviceProductList")
    public Object deviceProductList(){
        DeviceProductQuery deviceProductQuery = new DeviceProductQuery();
        return deviceTiktokInfoService.deviceProductList(deviceProductQuery);
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "抖音设备转移授权时间", notes = "抖音设备转移授权时间")
    @ApiOperationSupport(order = 23)
    @PostMapping("/deviceTiktokInfo/transferAuthTime")
    public Object transferAuthTime(@RequestBody TranferAuthTimeDto tranferAuthTimeDto){
        deviceTiktokInfoService.transferAuthTime(tranferAuthTimeDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除单个抖音设备机器人(是否转移数据)", notes = "删除单个抖音设备机器人(是否转移数据)")
    @ApiOperationSupport(order = 24)
    @PostMapping("/deviceTiktokInfo/delAndTransferData")
    public Object delAndTransferData(@RequestBody DelAndTransferDataDto delAndTransferDataDto){
        deviceTiktokInfoService.delAndTransferData(delAndTransferDataDto);
        return true;
    }

    @ApiOperation(value = "查询抖音设备机器人产品列表", notes = "查询抖音设备机器人产品列表")
    @ApiOperationSupport(order = 25)
    @PostMapping("/deviceTiktokInfo/findDeviceProductList")
    public Object findDeviceProductList(){
        List<SelectKeyVo> selectIdVoList = new ArrayList<>();
        TiktokDeviceProductKeyEnum[] tiktokDeviceProductKeyEnums = TiktokDeviceProductKeyEnum.values();
        if(tiktokDeviceProductKeyEnums != null){
            for (TiktokDeviceProductKeyEnum tiktokDeviceProductKeyEnum : tiktokDeviceProductKeyEnums){
                SelectKeyVo selectKeyVo = new SelectKeyVo();
                selectKeyVo.setKey(tiktokDeviceProductKeyEnum.getValue());
                selectKeyVo.setValue(tiktokDeviceProductKeyEnum.getDesc());
                selectIdVoList.add(selectKeyVo);
            }
        }
        return selectIdVoList;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "刷新抖音设备在线状态", notes = "刷新抖音设备在线状态")
    @ApiOperationSupport(order = 26)
    @PostMapping("/deviceTiktokInfo/refreshOnlineStatus")
    public Object refreshOnlineStatus(){
        deviceTiktokInfoService.refreshOnlineStatus(getLoginInfo().getMerId());
        return true;
    }

    @ApiOperation(value = "查询所有抖音设备机器人列表", notes = "查询所有抖音设备机器人列表", response = DeviceTiktokInfoVo.class)
    @ApiOperationSupport(order = 27)
    @PostMapping("/deviceTiktokInfo/findDeviceTiktokInfoSelect")
    public Object findDeviceTiktokInfoSelect(@RequestBody DeviceTiktokInfoQuery deviceTiktokInfoQuery){
        return deviceTiktokInfoService.findDeviceTiktokInfoSelect(deviceTiktokInfoQuery);
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "更新抖音设备手机版", notes = "更新抖音设备手机版")
    @ApiOperationSupport(order = 28)
    @PostMapping("/deviceTiktokInfo/updateMobileClientSoft")
    public Object updateMobileClientSoft(@RequestBody DeviceTiktokInfoIdDto deviceTiktokInfoIdDto){
        deviceTiktokInfoService.updateMobileClientSoft(deviceTiktokInfoIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量更新抖音设备手机版", notes = "批量更新抖音设备手机版")
    @ApiOperationSupport(order = 29)
    @PostMapping("/deviceTiktokInfo/batchUpdateMobileClientSoft")
    public Object batchUpdateMobileClientSoft(@RequestBody DeviceTiktokInfoIdListDto deviceTiktokInfoIdListDto){
        deviceTiktokInfoService.batchUpdateMobileClientSoft(deviceTiktokInfoIdListDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceTiktokInfo, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "增加抖音设备试用期授权", notes = "增加抖音设备试用期授权", response = Boolean.class)
    @ApiOperationSupport(order = 30)
    @PostMapping("/deviceTiktokInfo/addProbationAuth")
    public Object addProbationAuth(@RequestBody DeviceTiktokInfoAddProbationAuth deviceTiktokInfoAddProbationAuth){
        deviceTiktokInfoService.addProbationAuth(deviceTiktokInfoAddProbationAuth);
        return true;
    }
}
